package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.mapper.TravelMapper;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService {
    @Autowired
    private TravelCommendMapper travelCommendMapper;
    @Autowired
    private TravelMapper travelMapper;

    @Override
    public PageInfo query(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        //查询App需要的数据
        if (qo.getIsCommend()) {
            List list = travelCommendMapper.selectAppForList(qo);
            return new PageInfo(list);
        }else{//正常高查
            List list = travelCommendMapper.selectForList(qo);
            return new PageInfo(list);
        }
    }

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if (travelCommend.getId() != null) {
            //修改推荐
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }else{
            //新增推荐
            travelCommendMapper.insert(travelCommend);
            /*//修改游记的状态
            Travel travel = new Travel();
            travel.setId(travelCommend.getTravel().getId());
            travel.setState(Travel.STATUS_HOT);
            travelMapper.changeState(travel);*/
        }
    }
}
